﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BookTransactionControllers.Services;
using BookTransactionControllers.Connection;
using System.Data.SqlClient;
using System.Data;
using BookTransactionModels;

namespace BookTransactionControllers.Services_Impl
{
    public class DiaryTransactionManagerImpl : IDiaryTransactionServices, IMainServices
    {
        public bool Insert(DiaryTransactionBean diaryTransaction)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "Insert into [Diary]([IDBook1],[IDUser1],[IDBook2],[IDUser2],[Money],[Message]) Values (@IDBook1,@IDUser1,@IDUser2,@IDBook2,@Money,@Message)";
            command.Parameters.AddWithValue("@IDBook1",diaryTransaction.IDBook1);
            command.Parameters.AddWithValue("@IDUser1", diaryTransaction.IDUser1);
            command.Parameters.AddWithValue("@IDBook2", diaryTransaction.IDUser2);
            command.Parameters.AddWithValue("@IDUser2", diaryTransaction.IDBook2);
            command.Parameters.AddWithValue("@Money", diaryTransaction.Money);
            command.Parameters.AddWithValue("@Message", diaryTransaction.Message);
            return Connect.ExcuteNonQuery(command);
        }

        public bool Delete(SqlCommand command)
        {
            throw new NotImplementedException();
        }

        public DataTable SelectTableDiary(string UserID)
        {
            SqlCommand command = new SqlCommand();
            DataTable tblDiary;
            command.CommandText = "Select [User].FullName as Yourname, MyBook.Title as MyBook, YourBook.Title as YourBook, Mybook.SellingPrice as MoneyRoot, DiaryInfo.[Money] as MoneyAdd, DiaryInfo.[Message] From [User], Book as MyBook, Book as YourBook, (Select Diary.IDBook1, Diary.IDBook2, Diary.IDUser2, Diary.[Money], Diary.[Message] From Diary Where Diary.IDUser1 = @UserID) as DiaryInfo Where DiaryInfo.IDUser2 = [User].ID and DiaryInfo.IDBook2 = YourBook.ID and DiaryInfo.IDBook1 = MyBook.ID";
            command.Parameters.AddWithValue("@UserID", UserID);
            tblDiary = Connect.ExcuteQuery(command, "Diary");
            return tblDiary;
        }

        public bool Update(SqlCommand command)
        {
            throw new NotImplementedException();
        }


        public DataTable SelectTable(SqlCommand command, string tblName)
        {
            throw new NotImplementedException();
        }
    }
}
